package com.fengpanlong.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.UUID;

public class StringUtil {

	public static boolean isEmpty(String str) {
		if(str == null) {
			return true;
		} else if("".equals(str)) {
			return true;
		}
		return false;
	}
	
	public static boolean isNotEmpty(String str) {
		return !isEmpty(str);
	}

	public static String getId() {
		return UUID.randomUUID().toString();
	}

	public static String formateTime(String time) {
		long[] dates = {1000*60*60*24*30*12,1000*60*60*24*30,1000*60*60*24,1000*60*60,1000*60,1000,1};
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		GregorianCalendar gc = new GregorianCalendar();
		try {
			gc.setTime(sdf.parse(time));
		} catch (ParseException e) {
			e.printStackTrace();
		}
		long t = System.currentTimeMillis() - gc.getTimeInMillis();
		String str = null;
		if(t/dates[0] != 0) {
			str = t/dates[0] + "年前";
		} else if(t/dates[1] != 0) {
			str = t/dates[1] + "月前";
		} else if(t/dates[2] != 0) {
			str = t/dates[2] + "天前";
		} else if(t/dates[3] != 0) {
			str = t/dates[3] + "小时前";
		} else if(t/dates[4] != 0) {
			str = t/dates[4] + "分钟前";
		} else if(t/dates[5] != 0) {
			str = t/dates[5] + "秒前";
		}  else if(t/dates[6] != 0) {
			str = "1秒前";
		}
		return str;
	}
	public static String formateTime() {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return sdf.format(new Date());
	}

	public static List<String> parseEmployeesToString(String employees) {
		String[] list = employees.split(" ");
		List<String> employeesList = new ArrayList<String>();
		for(String str : list) {
			String str2 = str.trim(); 
			employeesList.add(str2);
		}
		return employeesList;
	}
}
